@isTest
private class ScheduledCargoGetNCDataControllerTest {
    static testMethod void testMethod1() {
    	Account acc = TestUtils.createAccount();
    	acc.Level__c = '一级医院';
        insert acc;
        
        ProductStructure__c ps = new ProductStructure__c();
        ps.Classify3__c = '试剂';
        insert ps;
        Product__c p1 = TestUtils.createProduct();
        p1.Category0__c = '试剂';
        p1.ProductStructure__c = ps.Id;
        p1.PriceCompany__c = 'MKSY';
        p1.NCCode__c = '000001';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        
        Product__c p2 = TestUtils.createProduct();
        p2.Category0__c = '试剂';
        p2.ProductStructure__c = ps.Id;
        p2.PriceCompany__c = 'MKSY';
        p2.NCCode__c = '000002';
        p2.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        insert new Product__c[] {p1, p2};


        ScheduledCargo__c sc = new ScheduledCargo__c();
        sc.Customer__c = acc.Id;

        insert sc ;

        SameBatchNumber__c sb = new SameBatchNumber__c();
        sb.CargoDetail__c = sc.Id;
        sb.Inventory__c = p1.Id;
        sb.SendMount2__c = 10;
        insert sb;

        ScheduledCargoGetNCDataController scgs = new ScheduledCargoGetNCDataController();
        scgs.sid = sc.Id;
        scgs.init();
        scgs.getNCData();
        ScheduledCargoPDFController scpdf = new ScheduledCargoPDFController();
        scpdf.scid = sc.Id;
        scpdf.init();


        PageReference page = new PageReference('/apex/ScheduledCargo?id=' + sc.Id);
        System.Test.setCurrentPage(page);
        ScheduledCargoController scc = new ScheduledCargoController();

        scc.getOldProductList();
        scc.getDetails();
        Map<String,String> sMap = new Map<String,String>();
        sMap.put('type','FromProduct');
        sMap.put('productName','productName');
        sMap.put('brand','brand');
        sMap.put('spec','spec');
        sMap.put('cate1','cate1');
        sMap.put('cate0','FromProduct');
        sMap.put('nccode','nccode');
        sMap.put('serialNo','FromProduct');
        scc.searchJson = EncodingUtil.urlEncode(JSON.serialize(sMap), 'UTF-8') ;
        scc.Search();

        List<ScheduledCargoController.SameBatchBean> sbList = new  List<ScheduledCargoController.SameBatchBean>();
        ScheduledCargoController.SameBatchBean sccsbb = new ScheduledCargoController.SameBatchBean(sb,null);
        sbList.add(sccsbb);
        scc.saveJson = EncodingUtil.urlEncode(JSON.serialize(sbList), 'UTF-8') ;
        scc.save();

        sc.Status__c = '已批准';
        sc.OwnerCompany__c = 'MKSY';
        update sc ;
        StockDetailsWebservice.postscargo(sc.Id);

    }
}